package com.online.shopping.service.impl;

import com.online.shopping.mapper.TbContentMapper;
import com.online.shopping.pojo.TbContent;
import com.online.shopping.pojo.TbContentExample;
import com.online.shopping.service.ContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Rui
 * @version 1.0
 * @date 2020/11/16 14:13
 */
@Service
public class ContentServiceImpl implements ContentService {
    @Autowired
    private TbContentMapper contentMapper;

    @Override
    public List<TbContent> findAllContent() {
        return contentMapper.selectByExample(null);
    }

    @Override
    public TbContent findContentById(Long id) {
        return contentMapper.selectByPrimaryKey(id);
    }

    @Override
    public int addContent(TbContent content) {
        return contentMapper.insert(content);
    }

    @Override
    public int updateContent(TbContent content) {
        return contentMapper.updateByPrimaryKeySelective(content);
    }

    @Override
    public void delContent(Long id) {
        contentMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void delManyContents(Long[] ids) {
        for (Long id : ids) {
            contentMapper.deleteByPrimaryKey(id);
        }
    }

    @Override
    public List<TbContent> selectByExample(TbContentExample example) {
        return contentMapper.selectByExample(example);
    }
}
